package com.haochu.novel.util;

import android.app.Activity;
import android.content.res.Resources;
import android.util.DisplayMetrics;


/**
 * @author Administrator
 *	测绘工具类
 */
public final class MeasureUtil {

	/**
	 * 获取屏幕宽度
	 */
	public static int getScreenWidth(Activity activity) {
		DisplayMetrics metrics = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		return metrics.widthPixels;
	}

	/**
	 * 获取屏幕高度
	 */
	public static int getScreenHeight(Activity activity) {
		DisplayMetrics metrics = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		return metrics.heightPixels;
	}
	
	/** 
     * dip与px之间转换 
     */  
	public static int dip2px(Resources resources, float dipValue) {  
        final float scale = resources.getDisplayMetrics().density;  
        return (int) (dipValue * scale + 0.5f);  
    }  
  
	public static int px2dip(Resources resources, float pxValue) {  
        final float scale = resources.getDisplayMetrics().density;  
        return (int) (pxValue / scale + 0.5f);  
    }  
	
}
